package org.nViron.nvParams;

//~--- non-JDK imports --------------------------------------------------------

import java.util.HashMap;

import org.nViron.nvParams.nvVizParamMgr.VIZPARAM;

/**
 * Caches vizualisations parameters that a frequently queried but only seldomly updated
 * @author Roland Haring <p>
 * <script type="text/javascript" src="http://www.ohloh.net/p/376434/widgets/project_basic_stats.js"></script>
 */
public class nvVizValueCache {
    private final HashMap vizValues = new HashMap();
    private nvVizCalculator vizCalc;

    public nvVizValueCache(nvVizCalculator vizCalc) {
        this.vizCalc = vizCalc;
    }

    public float getVizValue(VIZPARAM param) {
        Float val = (Float) vizValues.get(param);
        if (val == null){
            throw new NullPointerException("unknown viz param "+param.name());
        }
        return val.floatValue();
    }

    protected void setVizValue(VIZPARAM param, float val) {
        vizValues.put(param, new Float(val));
    }

    public void updateAllVizValues(nvVizParamMgr VizParamMgr) {
        for (int i = 0; i < VizParamMgr.size(); i++) {
            nvVizParam param = (nvVizParam) VizParamMgr.get(i);

            setVizValue(param.getKind(), vizCalc.calculateVizValue(param.getKind()));
        }
    }

    public void updateVizValue(VIZPARAM param) {
        setVizValue(param, vizCalc.calculateVizValue(param));
    }
}



